package com.xunlai.infra.permission.manager.web.converter;

import com.xunlai.infra.permission.manager.web.vo.role.CreateRolePermissionReqVo;
import com.xunlai.infra.permission.manager.web.vo.role.CreateRoleRelationVo;
import com.xunlai.infra.permission.manager.web.vo.role.CreateRoleReqVo;
import com.xunlai.infra.permission.manager.web.vo.role.QueryRoleReqVo;
import com.xunlai.infra.permission.manager.web.vo.role.RoleListVo;
import com.xunlai.infra.permission.storage.entity.Role;
import com.xunlai.infra.permission.storage.entity.RolePermission;
import com.xunlai.infra.permission.storage.entity.RoleRelation;
import javax.annotation.processing.Generated;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2024-02-21T19:26:01+0800",
    comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.5 (Amazon.com Inc.)"
)
public class RoleConverterImpl implements RoleConverter {

    @Override
    public Role convertCreateReq2Role(CreateRoleReqVo roleReqVo) {
        if ( roleReqVo == null ) {
            return null;
        }

        Role.RoleBuilder role = Role.builder();

        role.roleName( roleReqVo.getRoleName() );
        role.roleCode( roleReqVo.getRoleCode() );
        role.type( roleReqVo.getType() );
        role.enable( roleReqVo.getEnable() );

        return role.build();
    }

    @Override
    public RoleRelation convertCreateReq2RoleRelation(CreateRoleRelationVo createRoleRelationVo) {
        if ( createRoleRelationVo == null ) {
            return null;
        }

        RoleRelation.RoleRelationBuilder roleRelation = RoleRelation.builder();

        roleRelation.roleId( createRoleRelationVo.getRoleId() );
        roleRelation.roleCode( createRoleRelationVo.getRoleCode() );
        roleRelation.targetId( createRoleRelationVo.getTargetId() );
        roleRelation.targetType( createRoleRelationVo.getTargetType() );

        return roleRelation.build();
    }

    @Override
    public RolePermission convertCreateReq2RolePermission(CreateRolePermissionReqVo createRolePermissionReqVo) {
        if ( createRolePermissionReqVo == null ) {
            return null;
        }

        RolePermission.RolePermissionBuilder rolePermission = RolePermission.builder();

        rolePermission.roleId( createRolePermissionReqVo.getRoleId() );
        rolePermission.roleCode( createRolePermissionReqVo.getRoleCode() );
        rolePermission.resourceId( createRolePermissionReqVo.getResourceId() );
        rolePermission.resourceType( createRolePermissionReqVo.getResourceType() );
        rolePermission.resourceSource( createRolePermissionReqVo.getResourceSource() );

        return rolePermission.build();
    }

    @Override
    public Role convertQueryReq2Role(QueryRoleReqVo queryRoleReqVo) {
        if ( queryRoleReqVo == null ) {
            return null;
        }

        Role.RoleBuilder role = Role.builder();

        role.roleName( queryRoleReqVo.getRoleName() );
        role.roleCode( queryRoleReqVo.getRoleCode() );
        role.type( queryRoleReqVo.getType() );
        role.enable( queryRoleReqVo.getEnable() );

        return role.build();
    }

    @Override
    public RoleListVo convert2RoleListVo(Role role) {
        if ( role == null ) {
            return null;
        }

        RoleListVo roleListVo = new RoleListVo();

        roleListVo.setRoleName( role.getRoleName() );
        roleListVo.setRoleCode( role.getRoleCode() );
        roleListVo.setType( role.getType() );
        roleListVo.setEnable( role.getEnable() );
        roleListVo.setId( role.getId() );
        roleListVo.setTenantId( role.getTenantId() );
        roleListVo.setCreateUser( role.getCreateUser() );
        roleListVo.setCreateTime( role.getCreateTime() );
        roleListVo.setUpdateUser( role.getUpdateUser() );
        roleListVo.setUpdateTime( role.getUpdateTime() );
        roleListVo.setDeleted( role.getDeleted() );

        return roleListVo;
    }
}
